from django.shortcuts import render
from django.http import JsonResponse


def chart_list(request):
    return render(request, 'chart_list.html')
def chart_line(request):
    """折线图数据"""
    legend = ['A公司', 'B公司', 'C公司', 'D公司', 'E公司']
    x_axis = ['1月', '2月', '3月', '4月', '5月', '6月']
    series_list = [
        {
            "name": 'A公司',
            "type": 'line',
            "stack": 'Total',
            "data": [120, 132, 101, 134, 230, 210]
        },
        {
            "name": 'B公司',
            "type": 'line',
            "stack": 'Total',
            "data": [220, 182, 191, 234, 330, 310]
        },
        {
            "name": 'C公司',
            "type": 'line',
            "stack": 'Total',
            "data": [150, 232, 201, 154, 330, 410]
        },
        {
            "name": 'D公司',
            "type": 'line',
            "stack": 'Total',
            "data": [320, 332, 301,  390, 330, 320]
        },
        {
            "name": 'E公司',
            "type": 'line',
            "stack": 'Total',
            "data": [820, 932, 934, 1290, 1330, 1320]
        }
    ]
    result={
       "status" :True,
        "data": {
            'legend': legend,
            'series_list': series_list,
            'x_axis': x_axis,
        }
    }
    return JsonResponse(result)

def chart_bar(request):
    """构造柱状图的数据"""
    legend = ["销量", "业绩"]
    x_axis = ['1月', '2月', '3月', '4月', '5月', '6月']
    series_list = [
        {
            "name": '销量',
            "type": 'bar',
            "data": [5, 20, 36, 10, 10, 20]
        },
        {
            "name": '业绩',
            "type": 'bar',
            "data": [15, 24, 39, 18, 10, 70]
        }
    ]
    result = {
        "status": True,
        "data": {
            'legend': legend,
            'series_list': series_list,
            'x_axis': x_axis,
        }
    }
    return JsonResponse(result)


def chart_pie(request):
    """构造饼图的数据"""
    db_data__list = [{"value": 1048, "name": 'IT部门'},
                     {"value": 735, "name": '运营部门'},
                     {"value": 580, "name": '管理部门'},
                     {"value": 484, "name": '新媒体部门'},
                     {"value": 300, "name": '财务部门'}]
    result = {
        "status": True,
        "data": db_data__list
    }
    return JsonResponse(result)
